package com.example.demo.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间转换工具类
 * Created by rex on 2017/7/17.
 */
public class TimeUtils {
    /**
     * 将一个毫秒时间转化为yyyyMMddHHmmss形式的字符串
     * @param time
     * @return
     */
    public static String MillToDate(long time) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//24小时制
        Date date = new Date();
        date.setTime(time);
        return simpleDateFormat.format(date);
    }

    public static String getTwoDayBefore() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");//24小时制
        Calendar calendar = Calendar.getInstance();
        long calendarTime = calendar.getTimeInMillis();
        calendarTime -= 2*24*60*60*1000;
        Date date = new Date();
        date.setTime(calendarTime);
        return simpleDateFormat.format(date);
    }


    public static void main(String[] args) {
//        long time = System.currentTimeMillis();
//        System.out.println(MillToDate(time));
        System.out.println(getTwoDayBefore());
    }

}
